home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / MACLIST.AML < prev    next >
Text File  |  1996-07-17  |  4KB  |  158 lines

  1. //--------------------------------------------------------------------
  2. // MACLIST.AML
  3. // Macro List, (C) 1993-1996 by nuText Systems
  4. //
  5. // This macro displays a scrollable list of macros, showing the macro
  6. // name and description for each macro in the list. Selecting a macro
  7. // from the list will run the macro. Pressing the <f1> key will display
  8. // a help window for the macro at the cursor.
  9. //
  10. // This macro calls the Helpmac macro.
  11. //
  12. // Usage:
  13. //
  14. // Select this macro from the Macro List (on the Macro menu), or run it
  15. // from the macro picklist <shift f12>.
  16. //--------------------------------------------------------------------
  17.  
  18. // compile time macros and function definitions
  19. include bootpath "define.aml"
  20.  
  21. // initial popup window dimensions
  22. constant maclist_width  = 72
  23.  
  24. // colors
  25. constant maclist_title_color        = color black on gray
  26. constant maclist_menu_color         = color white on blue
  27. constant maclist_menu_hotkey_color  = color yellow on blue
  28. constant maclist_menu_hilite_color  = color white on cyan
  29.  
  30. // load the macro list buffer
  31. maclist = loadbuf (bootpath "macro\\maclist.dat")
  32. if not maclist then
  33.   msgbox "Maclist.dat not found." "Error!"
  34.   return
  35. end
  36.  
  37. settype "popup"
  38.  
  39. // add macro
  40. // (duplicates allowed, any order)
  41. function add
  42.   variable macro, desc
  43.   dialog "Add Macro to List" 72 5 "c"
  44.   field "&Macro File:  >"  3  2 44 '' "_load"
  45.   field "&Description: >"  3  4 41
  46.   button "O&k"      62 2 8
  47.   button "Cancel"   62 4 8
  48.   if (getdialog ref macro ref desc) == 'Ok' and macro then
  49.     mpath = getbootpath + "macro\\"
  50.     macro = qualify (forceext macro 'x') mpath
  51.     if file? macro then
  52.       name = getname macro
  53.       dest = qualify name mpath
  54.       // copy macro, help, and source (if available)
  55.       if dest <> macro then
  56.         copyfile macro dest
  57.         copyfile (forceext macro 'dox') (forceext dest 'dox')
  58.         copyfile (forceext macro 'aml') (forceext dest 'aml')
  59.       end
  60.       name = name [1..(pos '.' name) - 1]
  61.       insline ' ' + name:-11 + desc
  62.       savebuf
  63.     else
  64.       msgbox (onname macro) + " not found"
  65.     end
  66.   end
  67. end
  68.  
  69. // remove macro
  70. function remove
  71.   line = gettext
  72.   macro = line [2..posnot ' ' line [1 : 11] 'r']
  73.   oldwindow = gotowindow (getprevwin)
  74.   // confirmation prompt
  75.   if (icompare _ConDel 'n') or
  76.      (icompare (popup "ok" "Delete " + macro + '?') "ok") then
  77.     delline
  78.     savebuf
  79.   end
  80.   gotowindow oldwindow
  81. end
  82.  
  83. // change macro description
  84. function change
  85.   line = gettext
  86.   macro = line [2..posnot ' ' line [1 : 11] 'r']
  87.   desc = line [13..TO_END]
  88.   desc = ask macro + " description" '' desc
  89.   if desc then
  90.     delchar MAX_COL 13
  91.     instext desc 13
  92.     savebuf
  93.   end
  94. end
  95.  
  96. function help
  97.   line = gettext
  98.   helpmacro line [2..pos ' ' line [2:11]]
  99. end
  100.  
  101. // keys
  102. // (note: <esc> and <enter> handled by popup window)
  103. key <ins>    add
  104. key <del>    remove
  105. key <ctrl c> change
  106. key <f1>     help
  107.  
  108. function onopen
  109.   setcolor north_title_color  maclist_title_color
  110.   setcolor menu_color         maclist_menu_color
  111.   setcolor menu_hotkey_color  maclist_menu_hotkey_color
  112.   setcolor menu_hilite_color  maclist_menu_hilite_color
  113.   setframe "+4"
  114.   menubar '' 4
  115.     item "{Enter}=Run"      call <enter>
  116.     item "{Ins}=Add"        add
  117.     item "{Del}=Remove"     remove
  118.     item "{Ctrl-C}=Change"  change
  119.     item "{F1}=Help"        help
  120.     item "{Esc}=Exit"       close
  121.   end
  122.   if (getcoord 'y') + 2 <= getvidrows then
  123.     sizewindow 0 0 0 2
  124.   end
  125.   setwinctrl "≡" 2
  126. end
  127.  
  128. // display the popup menu
  129. line = popup maclist "Macro    Description"
  130.              maclist_width getvidrows - 10 (getcurrobj)
  131.  
  132. // destroy the menu
  133. destroybuf maclist
  134.  
  135. // run the selected macro
  136. if line then
  137.   macro = line [1..posnot ' ' line [1 : 11] 'r']
  138.  
  139.   // separate file and parameter (if any)
  140.   variable parameter
  141.   splitstr ' ' macro ref macro ref parameter
  142.  
  143.   // queue for execution to minimize interpreter stack usage
  144.   case locase macro
  145.     // full installation
  146.     when "install"
  147.       queue "runmacro" (bootpath macro + ".x")
  148.  
  149.     // lite installation
  150.     when "installs"
  151.       queue "runmacro" (bootpath macro [1..7] + ".x") '' "installs.dat" "Lite "
  152.  
  153.     otherwise
  154.       queue "runmacro" getbootpath + "macro\\" + macro + ".x"  '' parameter
  155.   end
  156.  
  157. end
  158.